ctrl_if_send_response(msg);
}
-static int balloon_write(struct file *file, const char *buffer,
- size_t count, loff_t *offp)
+static int balloon_write(struct file *file, const char __user *buffer,
+ unsigned long count, void *data)
{
char memstring[64], *endchar;
- int len, i;
unsigned long long target_bytes;
if ( !capable(CAP_SYS_ADMIN) )
return -EPERM;
+ if ( count <= 1 )
+ return -EBADMSG; /* runt */
if ( count > sizeof(memstring) )
- return -EFBIG;
-
- len = strnlen_user(buffer, count);
- if ( len == 0 )
- return -EBADMSG;
- if ( len == 1 )
- goto out; /* input starts with a NUL char */
- if ( strncpy_from_user(memstring, buffer, len) < 0 )
- return -EFAULT;
+ return -EFBIG; /* too long */
- endchar = memstring;
- for ( i = 0; i < len; ++i, ++endchar )
- if ( (memstring[i] < '0') || (memstring[i] > '9') )
- break;
- if ( i == 0 )
- return -EBADMSG;
+ if ( copy_from_user(memstring, buffer, count) )
+ return -EFAULT;
+ memstring[sizeof(memstring)-1] = '\0';
- target_bytes = memparse(memstring,&endchar);
+ target_bytes = memparse(memstring, &endchar);
set_new_target(target_bytes >> PAGE_SHIFT);
- out:
- *offp += len;
- return len;
+ return count;
}
-static int balloon_read(struct file *filp, char *buffer,
- size_t count, loff_t *offp)
+static int balloon_read(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
{
- char *priv_buf;
int len;
- priv_buf = (char *)__get_free_page(GFP_KERNEL);
- if ( priv_buf == NULL )
- return -ENOMEM;
-
#define K(_p) ((_p)<<(PAGE_SHIFT-10))
len = sprintf(
- priv_buf,
+ page,
"Current allocation: %8lu kB\n"
"Target allocation: %8lu kB / %8lu kB (actual / requested)\n"
"Unused heap space: %8lu kB / %8lu kB (low-mem / high-mem)\n"
if ( hard_limit != ~0UL )
len += sprintf(
- priv_buf + len,
+ page + len,
"%8lu kB (inc. %8lu kB driver headroom)\n",
K(hard_limit), K(driver_pages));
else
len += sprintf(
- priv_buf + len,
+ page + len,
" ??? kB\n");
- len -= *offp;
- if ( len > count)
- len = count;
- if ( len < 0 )
- len = 0;
-
- if ( len != 0 )
- (void)copy_to_user(buffer, &priv_buf[*offp], len);
-
- free_page((unsigned long)priv_buf);
-
- *offp += len;
+ *eof = 1;
return len;
}
-static struct file_operations balloon_fops = {
- .read = balloon_read,
- .write = balloon_write
-};
-
static int __init balloon_init(void)
{
unsigned long pfn;
return -1;
}
- balloon_pde->proc_fops = &balloon_fops;
+ balloon_pde->read_proc = balloon_read;
+ balloon_pde->write_proc = balloon_write;
(void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx, 0);